const { app, BrowserWindow } = require('electron')
const path = require('path')

// 测试生产环境文件加载
function createTestWindow() {
  const testWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: false,
      contextIsolation: true
    }
  })

  // 模拟生产环境路径
  const indexPath = path.join(__dirname, 'dist', 'index.html')
  console.log('尝试加载文件:', indexPath)
  
  testWindow.loadFile(indexPath)
    .then(() => {
      console.log('文件加载成功!')
    })
    .catch((error) => {
      console.error('文件加载失败:', error)
    })

  testWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
    console.error('页面加载失败:', errorCode, errorDescription)
  })

  testWindow.webContents.on('dom-ready', () => {
    console.log('DOM 加载完成')
  })
}

app.whenReady().then(createTestWindow)

app.on('window-all-closed', () => {
  app.quit()
})